/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
public class Conference implements Serializable {

    private long id;
    private List<Topic> topics;
    private Location location;
    private Date startSubmission;
    private Date endSubmission;
    private Date startReview;
    private Date endReview;
    private Date startRegistration;
    private Date endRegistration;
    private Date startDate;
    private Date endDate;
    private String title;
    private String description;
    private List<Event> events;

    public Conference() {
    }

    public Conference(Location location, Date startDate, Date endDate) {
        this.location = location;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public Conference(List<Topic> topics, Location location, Date startSubmission, Date endSubmission, Date startReview, Date endReview, Date startRegistration, Date endRegistration, Date startDate, Date endDate) {
        this.topics = topics;
        this.location = location;
        this.startSubmission = startSubmission;
        this.endSubmission = endSubmission;
        this.startReview = startReview;
        this.endReview = endReview;
        this.startRegistration = startRegistration;
        this.endRegistration = endRegistration;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public void updateTo(Conference other) {
        other.topics = topics;
        other.location = location;
        other.startSubmission = startSubmission;
        other.endSubmission = endSubmission;
        other.startReview = startReview;
        other.endReview = endReview;
        other.startRegistration = startRegistration;
        other.endRegistration = endRegistration;
        other.startDate = startDate;
        other.endDate = endDate;
        other.title = title;
        other.description = description;
        other.events = events;
    }
    
    

    @Override
    public String toString() {
        return "Conference{" + "id=" + id + ", topics=" + topics + ", location=" + location + ", startSubmission=" + startSubmission + ", endSubmission=" + endSubmission + ", startReview=" + startReview + ", endReview=" + endReview + ", startRegistration=" + startRegistration + ", endRegistration=" + endRegistration + ", startDate=" + startDate + ", endDate=" + endDate + ", title=" + title + ", description=" + description + '}';
    }

    private static boolean checkTimeLine(Date[] date) {
        for (int i = 0; i < date.length; i++) {
            Date previousDate = date[i];
            if (previousDate != null) {
                for (int j = i; j < date.length; j++) {
                    Date nextDate = date[j];
                    if (nextDate != null && previousDate.after(nextDate)) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public boolean isValid() {
        boolean valid = true;
//        valid &= location != null;
        valid &= checkTimeLine(
                new Date[]{
                    startSubmission, endSubmission, startReview, endReview,
                    startRegistration, endRegistration, startDate, endDate
                });
        valid &= startDate != null && endDate != null;
        return valid;
    }

    /**
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the topics
     */
    public List<Topic> getTopics() {
        if (topics == null) {
            topics = new ArrayList<>();
        }
        return topics;
    }

    /**
     * @param topics the topics to set
     */
    public void setTopics(List<Topic> topics) {
        this.topics = topics;
    }

    /**
     * @return the location
     */
    public Location getLocation() {
        return location;
    }

    /**
     * @param location the location to set
     */
    public void setLocation(Location location) {
        this.location = location;
    }

    /**
     * @return the startSubmission
     */
    public Date getStartSubmission() {
        return startSubmission;
    }

    /**
     * @param startSubmission the startSubmission to set
     */
    public void setStartSubmission(Date startSubmission) {
        this.startSubmission = startSubmission;
    }

    /**
     * @return the endSubmission
     */
    public Date getEndSubmission() {
        return endSubmission;
    }

    /**
     * @param endSubmission the endSubmission to set
     */
    public void setEndSubmission(Date endSubmission) {
        this.endSubmission = endSubmission;
    }

    /**
     * @return the startReview
     */
    public Date getStartReview() {
        return startReview;
    }

    /**
     * @param startReview the startReview to set
     */
    public void setStartReview(Date startReview) {
        this.startReview = startReview;
    }

    /**
     * @return the endReview
     */
    public Date getEndReview() {
        return endReview;
    }

    /**
     * @param endReview the endReview to set
     */
    public void setEndReview(Date endReview) {
        this.endReview = endReview;
    }

    /**
     * @return the startRegistration
     */
    public Date getStartRegistration() {
        return startRegistration;
    }

    /**
     * @param startRegistration the startRegistration to set
     */
    public void setStartRegistration(Date startRegistration) {
        this.startRegistration = startRegistration;
    }

    /**
     * @return the endRegistration
     */
    public Date getEndRegistration() {
        return endRegistration;
    }

    /**
     * @param endRegistration the endRegistration to set
     */
    public void setEndRegistration(Date endRegistration) {
        this.endRegistration = endRegistration;
    }

    /**
     * @return the startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    public List<Event> getEvents() {
        if (events == null) {
            events = new ArrayList<>();
        }
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }
}
